/**
 *
 */
package tec.data.persistence.oracle;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public abstract class OracleConnection {
	public static Connection createThinConnection() throws SQLException {
		return(new OracleThinConnection().createConnection());
	}
	
	public static Connection createOCIConnection() throws SQLException {
		return(new OracleOCIConnection().createConnection());
	}
	
	private static class OracleThinConnection extends OracleConnection {
		@Override
		protected Connection createConnection() throws SQLException {
			// register oracle driver
			//Class.forName("oracle.jdbc.driver.OracleDriver");
			
			// alternative method to register oracle driver
			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
			
			/*
			 * Oracle connection string : 
			 * - jdbc:oracle:thin:@host:port:sid
			 * - jdbc:oracle:thin:user/password@host:port:sid
			 */
			String url = "jdbc:oracle:thin:@localhost:1521:orcl";
			String user = "joe";
			String password = "741114";
			Connection con = DriverManager.getConnection(url, user, password);
			
			return(con);
		}
	}
	
	private static class OracleOCIConnection extends OracleConnection {
		@Override
		protected Connection createConnection() throws SQLException {
			/*
			 * Oracle connection string:
			 * - jdbc:oracle:oci:@tnsname
			 * - jdbc:oracle:oci:user/password@tnsname
			 */
			String url = "jdbc:oracle:oci:@orcl";
			String user = "joe";
			String password = "741114";
			Connection con = DriverManager.getConnection(url, user, password);
			
			return(con);		
		}
	}
	
	protected abstract Connection createConnection() throws SQLException;
}